import pandas as pd
import numpy as np

# 创建DataFrame
tradedays = pd.DataFrame(data={'open': [16.86, 16.76, 17.16, 17.22, 17.33],
                               'close': [16.48, 16.82, 16.75, 17.17, 17.22],
                               'exchange': [2.49, 1.82, 1.82, 2.49, 2.31],
                               'ex_dividend_date': [0, 1, 1, 1, 0]},
                         index=['20211231', '20211230', '20211229', '20211228', '20211227'])

# 新数据
new_data = {'open': 17,
            'close': 17,
            'exchange': round(np.random.uniform(1, 3), 2),
            'ex_dividend_date': np.random.choice([0, 1])}

# 将新数据转换成DataFrame，并设置索引值为'20211224'
new_row = pd.DataFrame(data=new_data, index=['20211224'])

# 插入新数据
tradedays = tradedays[:-1].append(new_row).append(tradedays[-1:])

print(tradedays)
